# Maintainer: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Contributor: William Rea <sillywilly@gmail.com>

pkgname=fbreader
pkgver=0.99.4
pkgrel=12
pkgdesc="An e-book reader for Linux"
arch=('loong64' 'x86_64')
url="http://www.fbreader.org/"
license=('GPL')
depends=('fribidi' 'bzip2' 'curl' 'qt5-base' 'libunibreak' 'sqlite')
source=(https://p5n.pp.ru/~sergej/dl/fbreader-sources-$pkgver.tgz
	fbreader-0.99.4.patch
	fbreader-gcc6.patch
	fbreader-qt5.patch)
sha256sums=('3d7c31d5ea314589d2a963290ad16f4d3d631a41e802b8b39f8be0c9f71eb8e9'
            'cb3aa6795c8f7c694ba296f6f6e6a7939648578a289bc84c10f8302c7e72df86'
            'bc67b538c51a5b77468469df6b5e96ce918ee11a5ff4e88e398ad5661d322f9c'
            '9d00f95f2a026b7bdafa6ab8519659cd2c293f1b9b00681a62d3f4992399e716')

prepare() {
  cd "$srcdir"/fbreader-$pkgver
  patch -p1 <"$srcdir"/fbreader-0.99.4.patch

  patch -p0 -i ../fbreader-gcc6.patch # Fix build with GCC6 (Gentoo)
  patch -p1 -i ../fbreader-qt5.patch # Port to Qt5 (Gentoo)

# Use system FLAGS
  sed -e "s/^CFLAGS = -pipe/CFLAGS +=/" -i makefiles/arch/desktop.mk
  sed -e "/^	CFLAGS +=/d" -i makefiles/config.mk
  sed -e "/^	LDFLAGS += -s$/d" -i makefiles/config.mk
  sed -e "/^LDFLAGS =$/d" -i makefiles/arch/desktop.mk
  sed -e 's|which ccache >|which ccache 2>|' -i makefiles/arch/desktop.mk
}

build() {
  export TARGET_ARCH=desktop
  export UI_TYPE=qt4
  export TARGET_STATUS=release
  export CXXFLAGS+=' -fPIC'
  cd fbreader-$pkgver
  make
}

package() {
  cd fbreader-$pkgver
  export CXXFLAGS+=' -fPIC'
  make DESTDIR="$pkgdir" install
}
